<?php 
class shopProductModel extends CDBModelBase {
	public function getTabelName(){
		return "t_shop_product";
	}

	public function getPKID(){
		return "p_id";
	}
	
	protected function getSequence()
	{
		return "SHOP_PRODUCT_SEQUENCE";
	}
	
	public function setTop($id,$type)
	{
		$param = array(
			array(":".$this->getPKID(), $id,PDO::PARAM_INT),
			array(":is_top", $type,PDO::PARAM_INT)
		);
		
		return $this->db->executeNonQuery("update ".$this->getTabelName()." set is_top=:is_top where ".$this->getPKID()."=:".$this->getPKID(),$param);
	}
	
	public function getNewShop($cityName)
	{
		$param = array(
				array(":city_name", $cityName,PDO::PARAM_STR)
		);
		
		$sql = "
			select sp.shop_id,sp.p_name,sp.pic_path,a.shop_simple_name,rownum row_id from t_shop_product sp, (select distinct t.shop_simple_name, t.shop_id from t_shop_community sc,t_community c,t_shop t 
			where t.shop_id=sc.shop_id and sc.community_id=c.community_id and c.city=:city_name and t.del_flag=0 order by t.shop_id desc) a where sp.shop_id=a.shop_id and rownum<=2";
    	
    	return $this->db->executeDataSet($sql,$param);
	}
	
	public function getTopShop($cityName)
	{
		$param = array(
				array(":city_name", $cityName,PDO::PARAM_STR)
		);
		
		$sql = "select sp.shop_id,sp.p_name,sp.pic_path,a.shop_simple_name,rownum row_id from t_shop_product sp, (select distinct t.shop_simple_name, t.shop_id from t_shop_community sc,t_community c,t_shop t 
			where t.shop_id=sc.shop_id and sc.community_id=c.community_id and c.city=:city_name and t.del_flag=0 order by t.shop_id desc) a where sp.shop_id=a.shop_id and sp.is_top=1 and rownum<=4 order by sp.sort_num desc";
    	
    	return $this->db->executeDataSet($sql,$param);
	}
}
?>
